home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / s_to_z / tstparse / main.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-15  |  4KB  |  168 lines

  1. {Demonstration program for BisonWare Parser V5.0}
  2. unit Main;
  3.  
  4. interface
  5.  
  6. uses
  7.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  8.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Menus, Parser, TabNotBk,
  9.   Grids;
  10.  
  11. type
  12.   TMainForm = class(TForm)
  13.     TabbedNotebook1: TTabbedNotebook;
  14.     LB1: TListBox;
  15.     Button1: TButton;
  16.     FP1: TFileParser;
  17.     Label1: TLabel;
  18.     Label2: TLabel;
  19.     Button2: TButton;
  20.     FP2: TFileParser;
  21.     SG1: TStringGrid;
  22.     CheckBox1: TCheckBox;
  23.     GroupBox1: TGroupBox;
  24.     radUpper: TRadioButton;
  25.     radLower: TRadioButton;
  26.     radNone: TRadioButton;
  27.     Label3: TLabel;
  28.     Label4: TLabel;
  29.     Label5: TLabel;
  30.     Label6: TLabel;
  31.     Label7: TLabel;
  32.     Label8: TLabel;
  33.     Panel1: TPanel;
  34.     Panel2: TPanel;
  35.     Panel3: TPanel;
  36.     Button3: TButton;
  37.     Label9: TLabel;
  38.     FP3: TFileParser;
  39.     memInput: TMemo;
  40.     LB2: TListBox;
  41.     CheckBox2: TCheckBox;
  42.     Label10: TLabel;
  43.     procedure Button1Click(Sender: TObject);
  44.     procedure FP1RecordParse(Sender: TObject);
  45.     procedure Button2Click(Sender: TObject);
  46.     procedure FP2RecordParse(Sender: TObject);
  47.     procedure CheckBox1Click(Sender: TObject);
  48.     procedure Button3Click(Sender: TObject);
  49.     procedure FormCreate(Sender: TObject);
  50.     procedure FP3RecordParse(Sender: TObject);
  51.     procedure FP3ParseError(Sender: TObject);
  52.     procedure CheckBox2Click(Sender: TObject);
  53.     procedure FormActivate(Sender: TObject);
  54.   end;
  55.  
  56. var
  57.   MainForm: TMainForm;
  58.   pcMemo: PChar;
  59.  
  60. implementation
  61.  
  62. {$R *.DFM}
  63.  
  64. {process the button 1 click event}
  65. procedure TMainForm.Button1Click(Sender: TObject);
  66. begin
  67.    {Clear out the list}
  68.    LB1.Items.Clear;
  69.  
  70.    {Start the Parse}
  71.    FP1.ParseFile;
  72. end;
  73.  
  74. procedure TMainForm.FP1RecordParse(Sender: TObject);
  75. begin
  76.     {Add a line to the listbox if required}
  77.     If FP1.FieldCount > 0 then
  78.         LB1.Items.Add(FP1.ParseList.strings[0]);
  79. end;
  80.  
  81. procedure TMainForm.Button2Click(Sender: TObject);
  82. begin
  83.     {Initialise the case conversion}
  84.     if radNone.Checked then
  85.         FP2.CaseConvert := ctNone;
  86.     if radUpper.Checked then
  87.         FP2.CaseConvert := ctUpper;
  88.     if radLower.Checked then
  89.         FP2.CaseConvert := ctLower;
  90.  
  91.     {Start the parse}
  92.     FP2.ParseFile;
  93. end;
  94.  
  95. procedure TMainForm.FP2RecordParse(Sender: TObject);
  96. var
  97.     suba: integer;
  98. begin
  99.     {Fill the grid from the parse list}
  100.     For suba := 1 to FP2.ParseList.Count do
  101.     begin
  102.         SG1.Cells[Suba-1,FP2.RecordCount - 1] := FP2.ParseList.Strings[suba -1];
  103.     end;
  104. end;
  105.  
  106. procedure TMainForm.CheckBox1Click(Sender: TObject);
  107. begin
  108.     {Decide what to do with text qualifiers}
  109.     if CheckBox1.State = cbUnchecked then
  110.         FP2.TrimTextQualifiers := False
  111.       else
  112.         FP2.TrimTextQualifiers := True;
  113. end;
  114.  
  115. procedure TMainForm.Button3Click(Sender: TObject);
  116. begin
  117.     {Point to the memo text}
  118.     FP3.ParsePChar := StrPCopy(pcMemo,memInput.Text);
  119.  
  120.     {Clear the output list box}
  121.     LB2.Items.Clear;
  122.  
  123.     {Parse the PChar}
  124.     FP3.ParseMemory;
  125. end;
  126.  
  127. procedure TMainForm.FormCreate(Sender: TObject);   
  128. begin
  129.     {Allocate some memory}
  130.     pcMemo := StrAlloc(255);
  131. end;
  132.  
  133. procedure TMainForm.FP3RecordParse(Sender: TObject);
  134. begin
  135.     {Allocate the parse list to the output listbox}
  136.     If FP3.FieldCount > 0 then
  137.         LB2.Items := FP3.ParseList;
  138. end;
  139.  
  140. procedure TMainForm.FP3ParseError(Sender: TObject);
  141. begin
  142.     {Tell the user about a unterminated text error}
  143.     if FP3.ErrorCode = 3 then
  144.         MessageDlg('Unterminated text string',mtInformation, [mbOK], 0);
  145.  
  146.     {Tell the user about a unterminated comment error}
  147.     if FP3.ErrorCode = 4 then
  148.         MessageDlg('Unterminated Comment',mtInformation, [mbOK], 0);
  149. end;
  150.  
  151. procedure TMainForm.CheckBox2Click(Sender: TObject);
  152. begin
  153.     {Set comment delimiters as per the users wishes}
  154.     If CheckBox2.Checked then
  155.         FP1.CommentDelimiters := '{ }'
  156.       else
  157.         FP1.CommentDelimiters := '';
  158. end;
  159.  
  160. procedure TMainForm.FormActivate(Sender: TObject);
  161. begin
  162.     {Centre the form on the screen}
  163.     MainForm.Left := (Screen.Width - MainForm.Width) div 2;
  164.     MainForm.Top := (Screen.Height - MainForm.Height) div 2;
  165. end;
  166.  
  167. end.
  168.